/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package co.edu.uniminuto.Videominuto.entities;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author JULIAN
 */
@Entity
@Table(name = "persona_video")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "PersonaVideo.findAll", query = "SELECT p FROM PersonaVideo p"),
    @NamedQuery(name = "PersonaVideo.findByIsanVdi", query = "SELECT p FROM PersonaVideo p WHERE p.personaVideoPK.isanVdi = :isanVdi"),
    @NamedQuery(name = "PersonaVideo.findByIdPersona", query = "SELECT p FROM PersonaVideo p WHERE p.personaVideoPK.idPersona = :idPersona"),
    @NamedQuery(name = "PersonaVideo.findByTipo", query = "SELECT p FROM PersonaVideo p WHERE p.tipo = :tipo")})
public class PersonaVideo implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected PersonaVideoPK personaVideoPK;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 10)
    @Column(name = "tipo")
    private String tipo;
    @JoinColumn(name = "id_persona", referencedColumnName = "id_persona", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Persona persona;
    @JoinColumn(name = "isan_vdi", referencedColumnName = "isan_video", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Video video;

    public PersonaVideo() {
    }

    public PersonaVideo(PersonaVideoPK personaVideoPK) {
        this.personaVideoPK = personaVideoPK;
    }

    public PersonaVideo(PersonaVideoPK personaVideoPK, String tipo) {
        this.personaVideoPK = personaVideoPK;
        this.tipo = tipo;
    }

    public PersonaVideo(int isanVdi, int idPersona) {
        this.personaVideoPK = new PersonaVideoPK(isanVdi, idPersona);
    }

    public PersonaVideoPK getPersonaVideoPK() {
        return personaVideoPK;
    }

    public void setPersonaVideoPK(PersonaVideoPK personaVideoPK) {
        this.personaVideoPK = personaVideoPK;
    }

    public String getTipo() {
        return tipo;
    }

    public void setTipo(String tipo) {
        this.tipo = tipo;
    }

    public Persona getPersona() {
        return persona;
    }

    public void setPersona(Persona persona) {
        this.persona = persona;
    }

    public Video getVideo() {
        return video;
    }

    public void setVideo(Video video) {
        this.video = video;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (personaVideoPK != null ? personaVideoPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof PersonaVideo)) {
            return false;
        }
        PersonaVideo other = (PersonaVideo) object;
        if ((this.personaVideoPK == null && other.personaVideoPK != null) || (this.personaVideoPK != null && !this.personaVideoPK.equals(other.personaVideoPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "co.edu.uniminuto.Videominuto.entities.PersonaVideo[ personaVideoPK=" + personaVideoPK + " ]";
    }
    
}
